
function CE = Welfare_4(Wi,Ppaid,oop,gamma,iX,rho,Nstates)
    T = size(Ppaid,1);
    C = Wi-Ppaid-oop;
    u = -1/gamma*exp(-gamma*1000*C);
    Num = mean(sum(u.*(iX~=(Nstates+1)).*power(rho,(1:T)-1)',1));
    Den = mean(sum((iX~=(Nstates+1)).*power(rho,(1:T)-1)',1));
    CE = -log(-gamma*Num/Den)/gamma;
end